//
//  CXLTabBarController.m
//  WYNews
//
//  Created by 夜猫子 on 2017/3/18.
//  Copyright © 2017年 夜猫子. All rights reserved.
//

#import "CXLTabBarController.h"

@interface CXLTabBarController ()

@end

@implementation CXLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self childViewController];
}

-(void)childViewController {
    
    
    NSArray *arr = @[
                     @{@"clsName": @"CXLHomeController", @"title": @"首页", @"icon": @"news"},
                     @{@"clsName": @"UIViewController", @"title": @"阅读", @"icon": @"reader"},
                     @{@"clsName": @"UIViewController", @"title": @"视频", @"icon": @"media"},
                     @{@"clsName": @"UIViewController", @"title": @"话题", @"icon": @"found"},
                     @{@"clsName": @"UIViewController", @"title": @"我", @"icon": @"me"}
                     ];
    
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSDictionary *dict in arr) {
        
        [arrM addObject:[self chileNavigationWithDict:dict]];
        
    }
    
    self.viewControllers = arrM;
    
}


- (UINavigationController *)chileNavigationWithDict:(NSDictionary *)dict{
    
    Class cs = NSClassFromString(dict[@"clsName"]);
    UIViewController *vc = [[cs alloc]init];

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    
    vc.title= dict[@"title"];
    //正常状态图片

    UIImage *img = [[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_icon_%@_normal", dict[@"icon"]]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.image = img;
    
    //选中状态图片
    UIImage *selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_icon_%@_highlight", dict[@"icon"]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selectedImage;
    
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
    
    return nav;
    
}



@end
